package system2;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Test {
    public static Scanner sc = new Scanner(System.in);
    public static Queue<Infomations> list = new LinkedList<>();

    public static void main(String[] args) {
        System.out.println("------------欢迎登录留言板系统-------------");
        while (true){
            System.out.println("-------------主菜单-------------");
            System.out.println("1.查询留言");
            System.out.println("2.发布留言");
            System.out.println("3.退出系统");
            System.out.println("请输入您的选择：");
            int choice = sc.nextInt();
            switch (choice) {
                case 1:
                    query();
                    break;
                case 2:
                    add();
                    break;
                case 3:
                    System.out.println("退出系统");
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入错误，请重新输入！");
            }
        }
    }
    public static void query(){
        System.out.println("序号\t姓名\t标题\t内容\t时间");
        for (int i = 0; i < list.size(); i++) {
            Infomations infomations = list.poll();
            System.out.println(i+1+"\t"+infomations.getName()+"\t"+infomations.getTitle()+"\t"+infomations.getContent()+"\t"+infomations.getTime());
            list.offer(infomations);
        }
    }

    public static void add() {
        System.out.println("请输入姓名：");
        String name = sc.next();
        System.out.println("请输入标题：");
        String title = sc.next();
        System.out.println("请输入内容：");
        String content = sc.next();
        Date date = new Date();
        String time = new SimpleDateFormat("yyy年MM月dd日").format(date).toString();
        list.offer(new Infomations(name, title, content,time));
        System.out.println("发布成功！");
    }
}
